        $(function () {
				$.ajaxSetup({
					cache: false,
					headers: {
						"header":localStorage.getItem("token")
					}
				});
            $("#tt").datagrid({
            	idField : 'id',
            	title: "",
                url : basePath + "medicalHistory/page",
                width: "100%",  
                height: "550px",
                singleSelect : false, /* 是否选中一行 */
                pagination : true,/* 是否显示下面的分页菜单 */
                border:true,
                rowStyler: function() {
                	　　return 'height: 60px';
                	},
				onClickRow: function(index,row){
					$("#tt").datagrid("clearSelections");
				},
                rownumbers:true,
                columns : [ [  {field : 'id', checkbox: false,hidden:true},
								{field : 'hospital',title : '就诊医院',width : '18%',align : 'center'},
								{field : 'department1',title : '科室1',width : '10%',align : 'center'},
								{field : 'department2',title : '科室2',width : '10%',align : 'center'},
                                {field : 'visitDoctorTime',title : '就诊时间',width : '15%',align : 'center'},
								{field : 'symptom',title : '主要症状',width : '30%',align : 'center'},
								{field : 'op',title : '操作',width : '100',align : 'center',
								formatter:function(value,row,index){
									var id = row.id.toString();
									var del = '<a href="#" onclick="doDelete(\'' + id + '\')">删除</a>';
									var detail = '<a href="#" onclick="toDetailDlg(\'' + id + '\')">详情</a>';
									//var detail = "<a class='fonta' href='#' " + "onclick=toDetailDlg(" + row.id +");>详情<a/>";
									//var del = "<a class='fonta' href='#' " + "onclick=doDelete(" + row.id +");>删除<a/>";
									var blank = "&nbsp;&nbsp;|";
									return detail + blank + del;
								}
					}

                ]],
            	loadMsg : '数据加载中,请稍候......'
            }); 
  
            var p = $('#tt').datagrid('getPager');  
            $(p).pagination({  
                /*
				 * 页数文本框前显示的汉字 修改每页默认条数 搜索pageList在jquery.easyui.min.js中修改，
				 * 分页区下拉分页数量集合和默认每页分页条数 striped属性 交替行换色
				 */  
                beforePageText: '第',  
                afterPageText: '页    共 {pages} 页',  
                displayMsg: '当前显示 {from}-{to} 条记录,共 {total} 条记录'  
            });

        }
        );
        // 搜索
        function doSearch() {
            $('#tt').datagrid('load', {
				hospital: $('#hospital').val()
			});
        }
        
        function clearQry() {
			//$("#measureTime1").datebox("setValue","");
			//$("#measureTime2").datebox("setValue","");
			$("#qryForm")[0].reset();
			$("[name='measureTime1']").val("");
			$("[name='measureTime2']").val("");
			$("[name='timePeriod']").val("");
			$("[name='level']").val("");
			doSearch();
		}

		function add2() {
			window.location.href = basePath + 'navigator?page=/medicalHistory/add';
		}

        // 新增框修改框弹出
        function add(){
        	var title = "新增";
            $('#addDlg').dialog({
                title: title,
                width: 900,
                height: 500,
                closed: false,
                cache: false,
                href: basePath + 'navigator?page=/medicalHistory/add',
                modal: true,
				onLoad:function(){
					initComboboxData();
				},
				top: 0,
				left: 10
            });       	
        }

		function initComboboxData(){
			$('#hospitalId').combobox({
				//disabled:true,
				url:basePath + 'dict/loadCombobox/hospital/0',
				valueField:'id',
				textField:'name',
				prompt: '请选择...',
				editable:false,
				onLoadSuccess:function(){ //默认选中第一条数据
				},
				onChange:  function () {
					$("#addff #hospital").val($('#hospitalId').combobox('getText'));
					$('#department1Id').combobox({
						//disabled:true,
						url:basePath + 'dict/loadCombobox/hospital/' + $('#hospitalId').combobox('getValue'),
						valueField:'id',
						textField:'name',
						prompt: '请选择...',
						editable:false,
						onLoadSuccess:function(){ //默认选中第一条数据

						},
						onChange: function () {
							$("#addff #department1").val($('#department1Id').combobox('getText'));
							$('#department2Id').combobox({
								url:basePath + 'dict/loadCombobox/hospital/' + $('#department1Id').combobox('getValue'),
								valueField:'id',
								textField:'name',
								prompt: '请选择...',
								editable:false,
								onLoadSuccess:function(){ //默认选中第一条数据

								},
								onChange:  function () {
									$("#addff #department2").val($('#department2Id').combobox('getText'));
								}
							});
						}
					});
				}
			});
		}

        // 新增
        function submitAdd(){
			var v = $("#addff").form("validate");//验证通过为true
			if(!v){
				$.messager.alert('错误提示',"请填写完整信息!",'warning');
				return;
			}

			setBtnDisable("submitMedicalHistoryAddId");

			$.ajax({
				type:"post",
				url:basePath + "medicalHistory/add",
				beforeSend: function(request) {
					request.setRequestHeader("header", localStorage.getItem("token"));
				},
				data:$('#addff').serializeArray(),
				cache:false,
				dataType: "json",
				success:function(result) {
					$.messager.show({
						title:'提示',
						msg:result.result,
						timeout:3000,
						showType:'slide'
					});
					cancelDlg("addDlg");
					$('#tt').datagrid('reload');// 刷新
					setBtnEnable("submitMedicalHistoryAddId");
				}
			});
        } 


        // 删除
        function doDelete(id) {
        	$.messager.confirm('提示', '你确定要删除吗?',function(r){
        		if(r){
        			$.ajax({
                        type:"delete",
                        url:basePath + "medicalHistory/delete/" + id,
                        cache:false,
                        dataType: "json", // this is important
                        success:function(result) {
                         	$.messager.show({
                         		title:'提示',
                         		msg:'删除成功',
                         		timeout:5000,
                         		showType:'slide'
                         	});
                        	$('#tt').datagrid('reload');// 刷新
                        	rows.length=0;
                        }
                    });
        		}

        	})
        }


        //关闭弹窗
        function cancelDlg(dlgName){
        	$('#'+dlgName).dialog("close");
        }
        // 判断是否为空
        function isNull( str ){
        	if ( str == "" ) return true;
        	var regu = "^[ ]+$";
        	var re = new RegExp(regu);
        	return re.test(str);
        }


		function toDetailDlg(id) {
			var title = "详情";
			$('#detailDlg').css("top","0").dialog({
				title: title,
				width: 1000,
				height: 400,
				closed: false,
				cache: false,
				href: basePath+'medicalHistory/navigator?page=/medicalHistory/detail&id='+id,
				modal: true
			});

		}